using UnityEngine;
using System.Collections;

public class FadeFont : MonoBehaviour 
{
    private bool ready;
    private float amount = 3;
    private float i;
    private Color color;

    void Start()
    {
        color = transform.GetComponent<MeshRenderer>().material.GetColor("_Color");
    }

    void Update()
    {
        if (!ready)
        {
            if (transform.GetComponent<MeshRenderer>().material.GetColor("_Color").a != 0)
            {
                color.a = 0;
                transform.GetComponent<MeshRenderer>().material.SetColor("_Color", color);
            }
        }
        if (ready)
        {
            i += Time.deltaTime * amount;
            color.a = i;
            transform.GetComponent<MeshRenderer>().material.SetColor("_Color", color);

            if (i > 1)
            {
                Destroy(this);
            }
        }
    }

    public void FadeIn()
    {
        ready = true;
    }

	public void FadeOut () 
    {
        color.a = 0;
        transform.GetComponent<MeshRenderer>().material.SetColor("_Color", color);
	}
}
